<?php
namespace App\Http\Controllers\AppApi\My;

use App\Services\Admin\JobStaffService;
use App\Services\Admin\StaffService;
use Illuminate\Http\Request;

class RecruitController extends BaseController
{
    /**
     * 我的招聘
     * 制作者：九哥
     */

    protected $staff;
    protected $job;

    public function __construct()
    {
        parent::__construct();
        $this->job = new JobStaffService();
        $this->staff = new StaffService();
    }

    /**
     * 公司招聘，获取
     */
    public function getComJobList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        /*if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $resJob = $this->job->getComIndexByCid($uid);
        if (!$resJob) { return $this->toJson(-3); }
        $dataArr = $resJob;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 公司应聘详情，获取
     */
    public function getComJobShow(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
       /* if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $id = $request->id;
        $resJob = $this->job->getComShowById($id);
        if (!$resJob) { return $this->toJson(-3); }
        return $this->toJson(0,$resJob);
    }

    /**
     * 工人应聘，获取
     */
    public function getStaffJobList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
       /* if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $resJob = $this->job->getStaffIndexByUid($uid);
        if (!$resJob) { return $this->toJson(-3); }
        $dataArr = $resJob;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 工人应聘详情，获取
     */
    public function getStaffJobShow(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
       /* if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $id = $request->id;
        $resJob = $this->job->getJobShowById($id);
        if (!$resJob) { return $this->toJson(-3); }
        $dataArr = $resJob;
        return $this->toJson(0,$dataArr);
    }

//    /**
//     * 工人应聘，状态设置
//     */
//    public function setJobStaffStatus(Request $request)
//    {
//        if ($request->app_access!=$this->app_access) {
//            return $this->toJson(-1);
//        }
//        if ($request->app_access!=$this->app_access) {
//            return $this->toJson(-1);
//        }
//        $token = $request->token;
//        $type = $request->type;
//        $cate = $request->cate;
//        $id = $request->id;
//        $status = $request->status;
//        if (!$token) {
//            return $this->toJson(-2);
//        }
//        $uid = $this->accessGet($token);
//        if (!$uid) { return $this->toJson(-13); }
//        $resJob = $this->job->setStaffStatus($uid,$status);
//        if (!$resJob) { return $this->toJson(-3); }
//        $dataArr = $resJob;
//        return $this->toJson(0,$dataArr);
//    }

    /**
     * 工人简历资料
     */
    public function getResume(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
       /* if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
       /* if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $resData = $this->staff->getResume($uid);
        if (!$resData) { return $this->toJson(-3); }
        return $this->toJson(0,$resData);
    }

    /**
     * 工人搜索设置
     */
    public function setResume(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
      /*  if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $resume = $request->resume;
        $resData = $this->staff->setResume($uid,$resume);
        
      ///  var_dump($uid,$resume);exit;
        
        if (!$resData) { return $this->toJson(-3); }
        return $this->toJson(0);
    }

    /**
     * 企业设置面试邀请
     * 1拒绝投递，2邀请面试
     */
    public function setMeet(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
       /* if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $id = $request->job;
        $meet = $request->meet;
        $status = $meet==1 ? 2 : 3;
        $resData = $this->job->setStaffStatus($id,$status);
        if (!$resData) { return $this->toJson(-3); }
        return $this->toJson(0);
    }

    /**
     * 工人设置邀请结果
     * 1拒绝邀请，2面试中
     */
    public function setMeet2(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
      /*  if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $id = $request->job;
        $meet = $request->meet;
        $status = $meet==1 ? 4 : 5;
        $resData = $this->job->setStaffStatus($id,$status);
        if (!$resData) { return $this->toJson(-3); }
        return $this->toJson(0);
    }

    /**
     * 工人设置面试结果
     * 1面试失败，2面试成功
     */
    public function setFinish(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
       /* if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $id = $request->job;
        $meet = $request->meet;
        $status = $meet==1 ? 6 : 7;
        $resData = $this->job->setStaffStatus($id,$status);
        if (!$resData) { return $this->toJson(-3); }
        return $this->toJson(0);
    }

    /**
     * 获取面试评价
     */
    public function getComment(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
      /*  if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $recruit = $request->job;
        $resData = $this->job->getComment($uid,$recruit);
        if (!$resData) { return $this->toJson(-3); }
        return $this->toJson(0);
    }

    /**
     * 设置面试评价
     */
    public function setComment(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        /*if (!$token) {
            return $this->toJson(-2);
        }*/
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $recruit = $request->job;
        $level = $request->level;
        $detail = $request->detail;
        $resData = $this->job->getComment($uid,$recruit);
        if ($resData) { return $this->toJson(-45); }
        $dataArr = array(
            'uid' => $uid,
            'recruit' => $recruit,
            'level' => $level,
            'detail' => $detail,
        );
        $this->job->setComment($dataArr);
        return $this->toJson(0);
    }
}